home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- menuutil.c
-
- This reusable module contains routines for managing menus.
-
- Copyright © 1994, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include "def.h"
- #include "menuutil.h"
-
-
-
- /*----------------------------------------------------------------------------
- AdjustOneMenu
-
- Adjusts the state of a single menu.
-
- Entry: menuID = menu id of menu to adjust.
- numCommands = number of commands in menu.
- *oldStatePtr = old menu enable/disable flags.
- newState = new menu enable/disable flags.
-
- Exit: function result = true if menu bar must be redrawn.
- *oldStatePtr = updated menu enable/disable flags.
- ----------------------------------------------------------------------------*/
-
- Boolean AdjustOneMenu (short menuID, short numCommands,
- unsigned long *oldStatePtr, unsigned long newState)
- {
- unsigned long x, y, oldState;
- Boolean mustRedraw = false;
- short i;
- MenuHandle theMenu;
-
- if ((newState & 0xfffffffe) == 0) {
- newState = 0;
- } else {
- newState |= 1;
- }
- theMenu = GetMenuHandle(menuID);
- oldState = *oldStatePtr;
- if (oldState == newState) return false;
- if ((newState & 1) == 0) {
- if ((oldState & 1) == 0) return false;
- DisableItem(theMenu, 0);
- *oldStatePtr &= 0xfffffffe;
- return true;
- }
- if ((oldState & 1) == 0) {
- EnableItem(theMenu,0);
- mustRedraw = true;
- }
- x = oldState;
- y = newState;
- for (i = 1 ; i <= numCommands; i++) {
- x >>= 1;
- y >>= 1;
- if ((x & 1) != (y & 1)) {
- if ((y & 1) == 0) {
- DisableItem(theMenu, i);
- } else {
- EnableItem(theMenu, i);
- }
- }
- }
- *oldStatePtr = newState;
- return mustRedraw;
- }
-